/////precompiled////////
#include "precompiled.h"
////////////////////////


#include "prs_FrmButton.h"
#include "prs_FrmUseTemplate.h"

using namespace prs;

// TNodeFrmButtonControl //////////////////////////////////////////////////////

//
void TNodeFrmButtonControl::Click() {
  //TButton::UpdateDown(V);

  TMessage_ClickFrmButton M;
    M.Sender = &node;
  TNodeUseTemplate::sendMessage(M);
}

// TNodeFrmButton /////////////////////////////////////////////////////////////

//
TNodeFrmButtonControl *TNodeFrmButton::BuildControl(
  frm::control::TPanel *ParentControl
){
  TNodeFrmButtonControl *P = Control.GetValue();

  if (!P || &P->GetWindow() != &ParentControl->GetWindow()) {
    delete P; 
    P = new TNodeFrmButtonControl(ParentControl->GetWindow(),*this);
    Control.SetValue(P);
    ParentControl->AddChildLast(P,false);

    Geometry.Value.UnionTo(P->GetGeometry());
  }
  
  return P;
}

// TRuleFrmButton /////////////////////////////////////////////////////////////

//
TRuleFrmButton::TRuleFrmButton(
  snt::text::TContext &Context,
  svl::TVariant &VParentNode,
  TRuleFrmChildrenBase &RChildren,
  TRuleSetNodeIdOptionally &RSetNodeIdOptionally,
  TRuleFrmGeom &RFrmGeom,
  TRuleSetAttrValue &RSetAttrValue,
  TRuleSetStyle &RStyle
) 
:vParentNode(VParentNode)
,rGeometry(RFrmGeom)
{
  snt::text::TSequence T(Context);
  snt::text::TKeyword K(Context);
  snt::TFVoid F;
  TFuncNewNodeIntoAttrOldChildren FNewNode;
  snt::TReturn Return;

  this->Name(GetClassName()).Local(vParentNode)
  | K.New("button") & FNewNode.New(vParentNode,TNodeFrmButton()) 
    & RSetNodeIdOptionally.New() & RAttr.New() 
    & Return.New()
  ;
  
  RAttr
  | T.New("(") 
    & RAttr1.New() & RChildren.New() 
    & T.New(")") & Return.New()
  | Return.New()
  ;

  RAttr1
  | AAttr1.New()
  ;
  AAttr1
  | RSetAttrValue.New(
      VParentNode,
      TRuleSetAttrValue::TAttrs()
       .Add(TFrmDict::attrName_ControlId,this,&TRuleFrmButton::FSetParamControlId) 
    )
    & AAttr1.New()
  
  | RStyle.New() & AAttr1.New()
  | F.New(this,&TRuleFrmButton::FSetGeometry) & RFrmGeom.New() & AAttr1.New()
  | Return.New()
  ;
}
